package jam.model;

import java.util.*;
import java.util.concurrent.*;

//
// =============================================================================
//

/**
 * A model for a single client. 
 */
public class ClientModel {
    private Map<String, Channel> channels;
    private User user;
    
    //
    // =========================================================================
    //
    
    public Channel getChannel(String channelName) {
        return channels.get(channelName);
    }
    public Collection<Channel> getChannels() {
        return Collections.unmodifiableCollection(this.channels.values());
    }
   
    public boolean isInChannel(String channelName) {
        return this.channels.containsKey(channelName);
    }
    
    public void addChannel(Channel c) {
        this.channels.put(c.getName(), c);
    }
    
    public void removeChannel(String channelName) {
        this.channels.remove(channelName);
    }
    
    //
    // =========================================================================
    //
    
    public User getUser() { return this.user; }
	public synchronized void setUser(User user) { this.user = user; }
    
    //
    // =========================================================================
    //

    public boolean isLoggedIn() {
            return this.user != null;
    }

    //
    // =========================================================================
    //

    public ClientModel() {
            this.user = null;
    this.channels = new ConcurrentHashMap<String, Channel>();
    }
}
